package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.entity.Message;
import com.bcu.calculus.entity.Unpass;
import com.bcu.calculus.entity.UserInfo;
import com.bcu.calculus.mapper.UnpassMapper;
import com.bcu.calculus.mapper.UserinfoMapper;
import com.bcu.calculus.service.UnpassService;
import com.bcu.calculus.service.UserInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class UnpassServiceImpl implements UnpassService {

    @Resource
    private UnpassMapper unpassMapper;
    @Resource
    private UserinfoMapper userinfoMapper;

    @Override
    public Message<?> addUnpass(Unpass unpass) {
        return unpassMapper.insert(unpass)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> delUnpss(Integer unpassId) {
        return unpassMapper.deleteByPrimaryKey(unpassId)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> updateUnpass(Unpass unpass) {
        return unpassMapper.updateByPrimaryKeySelective(unpass)> 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<List<Unpass>> selectAll() {
        return Message.success(null).add(unpassMapper.selectAll());
    }

    @Override
    public Message<Unpass> selectOneByPrimaryKey(Integer unpassId) {
        return Message.success(null).add(unpassMapper.selectByPrimaryKey(unpassId));
    }

    @Override
    public Message<Unpass> selectOneByActId(Integer actId) {
        return Message.success(null).add(unpassMapper.selectOneByActId(actId));
    }

//    @Override
//    public Message<?> findAllRouterErrorInfo(String unPassInfo,String SemId) {
//        List<HashMap<String,Object>> maps = new ArrayList<>();
//        List<Unpass> unpassList = unpassMapper.findUnPassByNumberInfo(unPassInfo,SemId);
//        for (Unpass unPass:unpassList) {
//            HashMap<String,Object> map = new HashMap<>();
//            map.put("UnPass",unPass);
//            UserInfo userInfo = userinfoMapper.selectByPrimaryKey(unPass.getSend().getSendUserId());
//            userInfo.setUser(null);
//            map.put("UserInfo",userInfo);
//            maps.add(map);
//        }
//
//        return Message.success(null).add(maps);
//    }
}
